// register.js
function generatePhoneNumbers() {
    console.log('generatePhoneNumbers function called');
    var numbersDiv = document.getElementById('phone-numbers');
    numbersDiv.innerHTML = '';
    for (var i = 0; i < 9; i++) {
        var number = '139';
        for (var j = 0; j < 8; j++) {
            number += Math.floor(Math.random() * 10);
        }
        var span = document.createElement('span');
        span.className = 'phone-number';
        span.textContent = number;
        (function (num) {
            span.onclick = function () {
                document.getElementById('phone').value = num;
            };
        })(number);
        numbersDiv.appendChild(span);
    }
}

function validateForm() {
    var username = document.getElementById('username').value;
    if (username === '') {
        alert('用户名不能为空，请输入用户名！');
        return false;
    }
    var password = document.getElementById('password').value;
    if (password === '') {
        alert('密码不能为空，请输入密码！');
        return false;
    }
    var phone = document.getElementById('phone').value;
    if (phone === '') {
        alert('手机号不能为空，请选择手机号！');
        return false;
    }
    var balance = document.getElementById('balance').value;
    if (balance === '') {
        alert('预存金额不能为空，请输入预存金额！');
        return false;
    }
    const userpackage = document.getElementById('userpackage').value;
    let packagePrice;
    switch (userpackage) {
        case '1':
            packagePrice = 50;
            break;
        case '2':
            packagePrice = 60;
            break;
        case '3':
            packagePrice = 150;
            break;
        default:
            packagePrice = 0;
    }
    const errorMessage = document.querySelector('.error-message');
    if (parseFloat(balance) < packagePrice) {
        errorMessage.style.display = 'block';
        return false;
    } else {
        errorMessage.style.display = 'none';
        return true;
    }
}

window.onload = function () {
    console.log('Window loaded');
    generatePhoneNumbers();
    // 保留JSP脚本标签作为占位符，将在JSP中处理
    // 这里是一个标记，实际JS文件中不会有这个
    // __PHONE_EXISTS_ALERT__
};